
local LoginQueueView = class("LoginQueueView",function() 
	return display.newLayer("LoginQueueView")
end)

-- local QUEUE_TIP_STR = L("目前排队在 <font color='#00FF00'>第%s位</font>，前面有 <font color='#57aeef'>%s位</font> 玩家正在排队")
local QUEUE_TIP_STR = L("lua_code_text_107")
local WAIT_TIP_STR = L("lua_code_text_355")
-- local WAIT_TIP_STR = L("预计等待：<font color='#FF0000'>%s秒</font>")
local WAIT_TIP_STR_2 = L("lua_code_text_99")

local sformat = string.format

function LoginQueueView:ctor()
	local view,bindingNodes = cc.CSLoader:createNode(Res.LoginQueueScene,true, true, true)
    view:setContentSize(display.width,display.height)
	ccui.Helper:doLayout(view)
	view:setTouchEnabled(true)
	view:setSwallowTouches(true)
    self:addChild(view)

    self._timeline = view:getTimeline()
    self._timeline:play("open", false)

    self._ui = display.uiDelegate(view)

    self._ui.Button_back:setVisible(false)

    self._ui.Button_queding:addClickEventListener(function()
        self._timeline:play("close", false)
        self:performWithDelay(function()
    	   executeFunc(self._onClose)
        end, app:getAnimationInterval() * 9)
    end)
end

function LoginQueueView:onClose(cb)
	self._onClose = cb
end

function LoginQueueView:setZoneName(str)
	self._ui.server:setString(str)
end

function LoginQueueView:setQueueIndex(pos)
	self._pos = pos
	self._ui.tips_1:setString(sformat(QUEUE_TIP_STR, pos, pos-1))
end

function LoginQueueView:_refrehWaitTime()
	if self._scds > 0 then

		local duration 
		if self._scds >= 1800 then
			self._ui.tips_2:setString(sformat(WAIT_TIP_STR, L("lua_code_text_411")))
			duration = 5
		else
			duration = 1
			local min = math.floor(self._scds / 60)
			local sec = self._scds % 60
			local str = min > 0 and sformat(L("lua_code_text_415"), min, sec) or sformat(L("lua_code_text_131"), sec)
			self._ui.tips_2:setString(sformat(WAIT_TIP_STR, str))
		end
		self._ui.tips_2:performWithDelay(function()
			self._scds = self._scds - duration
			self:_refrehWaitTime()
		end, duration)
	else
		self._ui.tips_2:setString(WAIT_TIP_STR_2)
	end
end

function LoginQueueView:setWaitTime(t)
	self._scds = t
	self._ui.tips_2:stopAllActions()
	self:_refrehWaitTime()
end

return LoginQueueView